
package com.chuangan.releasetask.Utils;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.io.IOException;

/**
 * @Author: zihua
 * @Date: 2020/7/22 17:07
 * @Version 1.0
 */
public class ExcelDownloadUtil {


    public static HSSFWorkbook ExcelDownload(String[] header, String sheet, String filename)  throws IOException {

        //声明一个工作簿
        HSSFWorkbook workbook = new HSSFWorkbook();

        //生成一个表格，设置表格名称
        HSSFSheet hssfSheet = workbook.createSheet(sheet);

        //设置表格列宽度为10个字节
        hssfSheet.setDefaultColumnWidth(10);
        //创建标题的显示样式
        HSSFCellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setFillForegroundColor(IndexedColors.YELLOW.index);
        //创建第一行表头
        HSSFRow hssfRow = hssfSheet.createRow(0);

        //遍历添加表头
        for (int i = 0; i < header.length; i++) {
            //创建一个单元格
            HSSFCell cell = hssfRow.createCell(i);

            //创建一个内容对象
            HSSFRichTextString text = new HSSFRichTextString(header[i]);

            //将内容对象的文字内容写入到单元格中
            cell.setCellValue(text);
            cell.setCellStyle(headerStyle);
        }


        return workbook;










    }

}

